$(function () {
    $("#wx_picture,#qq_picture").hide();

    ajaxFirst(1);

});

function ajaxFirst(currentPage){
    var jsonStr = {pageSize: 8, pageNum: currentPage};
    $.ajax({
        type: "get",
        url: "/article/getArticle",
        data: jsonStr,
        contentType: "application/json",
        dataType: "json",
        success: function(data){
            putInArticle(data.content);
            scrollTo(0,0);// 返回顶部
            putPageHelper(data, currentPage);
        }
    })
}

function putInArticle(data){
    var article = $("#articleIndex");
    article.empty();
    $.each(data, function (index, obj) {
        var center = $(
            '<div class="item hj-center">' +
            '<div class="layui-fluid">'+
            '<div class="layui-row">' +
            '<div class="item-cont">' +
            '<h3>'+ obj["title"] + '</h3>' +
            // '<h5>设计文章</h5>' +
            '<p>' + obj["summary"] + '</p>' +
            '<a href="' + obj["articleUrl"] +'" class="go-icon"></a>' +
            '</div>' +
            '</div>' +
            '</div>' +
            '</div>');
        article.append(center);
    });
}

function putPageHelper(data, currentPage){
    var count = data.totalSize; //总记录数
    // 总页数大于页码总数
    layui.use('laypage', function () {
        var laypage = layui.laypage;
        // 执行一个laypage 实例
        laypage.render({
            elem: 'page-helper',
            groups: 5,// 默认的连续出现的页码
            count: count,// 数据总数
            limit: 8,// 每页展示条数
            curr: currentPage,// 起始页
            jump: function (obj, first) {// 跳转页码时调用
                if (!first){
                    currentPage = obj.curr;
                    ajaxFirst(currentPage, 0)
                }
            }
        })
    })
}



/**
 * 个人信息渲染
 */
$(".wxchat").mouseenter(function () {
    $("#wx_picture").show();
});
$(".wxchat").mouseleave(function () {
    $("#wx_picture").hide();
});
$(".qq").mouseenter(function () {
    $("#qq_picture").show();
});
$(".qq").mouseleave(function () {
    $("#qq_picture").hide();
});